package com.my.main;

import java.util.List;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.my.bean.ForWardBean;

public class App {

	public static void go() {  
        try {  
            JSch jsch = new JSch();  
            Session session = jsch.getSession(PropertiesUtil.GetValueByKey("gangway.name"),PropertiesUtil.GetValueByKey("gangway.address"),Integer.parseInt(PropertiesUtil.GetValueByKey("gangway.port")));
            session.setPassword(PropertiesUtil.GetValueByKey("gangway.pwd"));
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
            System.out.println(session.getServerVersion());//这里打印SSH服务器版本信息  
            
            List<ForWardBean> list = PropertiesUtil.getList();
            if(null!=list){
            	for(ForWardBean bean:list){
            		int assinged_port = session.setPortForwardingL(bean.getLocalPort(), bean.getAddress(), bean.getTargetPort());//端口映射 转发  
            		System.out.println("开启本地端口localhost:" + assinged_port);
            	}	
            }
        } catch (Exception e) {
            e.printStackTrace();  
        }
    }
	public static void main(String[] args) {
		String file = "C:/config/config.properties";
		if(null==args||args.length<1){
//			String file = ClassLoader.getSystemResource("config.properties").getPath().toString();
//			if(null!=file&&file.startsWith("file")){
//				file = file.replaceAll("file", "");
//			}
//			System.out.println("filepath="+file);
			PropertiesUtil.setFilePath(file);
		}else{
			for(String s:args){
				System.out.println(s);
			}
		}
		go();
	}
}
